package dymnd.ui.menu;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;

import dymnd.ui.ThemeConstants;

public class DrawerMenu extends JComponent implements ActionListener{

	private Container contentPane = new Container();
	
	private DrawerPane pane;
	public DrawerMenu(String title, int width, int height, DrawerPane pane)	{
		this.pane = pane;
		setLayout(null);
		setSize(width, height);
		setBorder(BorderFactory.createLineBorder(Color.gray));
		
		//add the menu and title section
		add(createTitleBar(title));
		
		
	}
	
	
	
	private static final int titlebarHeight = 10;
	private static final int titlebarCloseButtonWidth = 10;
	private Container createTitleBar(String title)	{
		Container c = new Container();
		Dimension size = getSize();
		c.setSize(size.width, titlebarHeight);
		c.setLocation(0, 0);
		c.setBackground(ThemeConstants.DRAWER_MENU_TITLEBAR_COLOR);
		
		JLabel titleLabel = new JLabel(title);
		//TODO: Consider changing the variable for storing this component's color
		titleLabel.setForeground(ThemeConstants.THEME_PLUGIN_PANEL_TEXT_COLOR);
		
		titleLabel.setSize(c.getWidth() - titlebarCloseButtonWidth, c.getHeight());
		titleLabel.setLocation(0, 0);
		c.add(titleLabel);
		
		//this is the close button for the drawer
		//TODO: Give this component an icon instead of an "X"
		JButton closeButton = new JButton("X");
		closeButton.setBackground(ThemeConstants.DRAWER_MENU_TITLEBAR_COLOR);
		closeButton.setForeground(ThemeConstants.THEME_PLUGIN_PANEL_TEXT_COLOR);
		
		closeButton.setSize(titlebarCloseButtonWidth, c.getHeight());
		closeButton.setLocation(titleLabel.getWidth(), 0);
		closeButton.setActionCommand("close");
		closeButton.addActionListener(this);
		
		c.add(closeButton);
		
		return c;
	}
	
	public void actionPerformed(ActionEvent e)	{
		if(e.getActionCommand() == "close")	{
			pane.drawerClosed(this);
		}
			
	}
	
}
